import Vue from "vue";
import Vuex from "vuex";
import text from './text';

Vue.use(Vuex);

export default new Vuex.Store({
	state: {
		userdata: [],
		musicList: [],
		nowsong: null,
		nowindex: 0,
		play: false,
		nowlist: "",
		currentTime: "",
	},
	mutations: {
		changeuserdata(state, obj) {
			state.userdata = obj;
		},
		addMusic(state, obj) {
			// if (JSON.stringify(state.musicList) !== "[]") {
			// 	state.nowindex++;
			// }
			Vue.axios({
				method: "get",
				url: "https://music.hzbiz.net/song/url",
				params: {
					id: obj.id,
				},
			})
				.then((result) => {
					state.play = true;
					obj.url = result.data.data[0].url;
					state.musicList.unshift(obj);
					state.musicList = [...new Set(state.musicList)];
					state.nowsong = obj;
					// console.log(state.musicList[0].id, state.nowindex, "123456");
				})
				.catch((err) => {
					console.log(err);
				});
		},
		changenowlis(state, obj) {
			state.nowlist = obj;
		},
		addclear(state) {
			state.musicList = [];
		},
		changecurrentTime(state, time) {
			state.currentTime = time;
		},
		changenowsong(state, obj) {
			state.nowsong = obj;
		},
	},
	actions: {},
	modules: {text},
});
